﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Nanohope_v1._0
{
    class Animation
    {
        private Texture2D texture;
        private int steps;
        private Vector2 imageSize;
        private int elapsedTime;
        private int frameTime;
        private int current;
        private Rectangle source;

        public Animation(int steps, int width, int height, Texture2D texture)
        {
            this.steps = steps;
            this.imageSize = new Vector2(width, height);
            this.texture = texture;
            frameTime = 40;
            current = 0;
            elapsedTime = 0;
        }

        public void Update(GameTime gameTime)
        {
            elapsedTime += (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (elapsedTime > frameTime)
            {
                current++;
                if (current == steps)
                {
                    current = 0;
                }
                elapsedTime = 0;
            }

            source = new Rectangle(current * (int)imageSize.X, 0, (int)imageSize.X, (int)imageSize.Y);
        }

        public void onDraw(SpriteBatch spriteBatch, Vector2 position, bool whatever)
        {
            if(whatever)
                spriteBatch.Draw(texture, position, source, Color.White);
            else
                spriteBatch.Draw(texture, position, source, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.FlipHorizontally, 0);         }

    }
}
